<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
  <title>汇总</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
   <link href="${server}/static/css/bootstrap.min.css" rel="stylesheet">
  <link href="${server}/static/css/bootstrap_new.css" rel="stylesheet">
  <link href="${server}/static/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
 <script type="text/javascript" src="${server}/static/js/jquery.min.js"></script>
 <script type="text/javascript"  src="${server}/static/js/bootstrap.min.js"></script>
  <script type="text/javascript"  src="${server}/static/js/bootstrap_new.js"></script>
  <script type="text/javascript"  src="${server}/static/js/bootstrap-datetimepicker.js"></script>
  <script type="text/javascript"  src="${server}/static/js/bootstrap-datetimepicker.zh-CN.js"></script>
  <style>
  .table>thead>tr>th{
  	font-size:6px
  }
  </style>
   <script type="text/javascript">
   var numberFlag = true;
   $(document).ready(function(){
		 if('${message}' !='' && '${message}' !='null' ){
			 setMessage("alert-warning",'${message}');
		 }
		$("[name=datetimepicker]").datetimepicker({
			 	useCurrent : true,
		        format: "yyyy-mm-dd",//设置时间格式，默认值: 'mm/dd/yyyy'
		        weekStart : 0, //一周从哪一天开始。0（星期日）到6（星期六）,默认值0
		        autoclose : true,//当选择一个日期之后是否立即关闭此日期时间选择器
		        startView : 2,//点开插件后显示的界面。0、小时1、天2、月3、年4、十年，默认值2
		       	minView: "month",//插件可以精确到那个时间，比如1的话就只能选择到天，不能选择小时了
		        todayHighlight : true,//是否高亮当前时间
		        language : 'zh-CN',//选择语言，前提是该语言已导入
		        pickerPosition: "bottom-left"
		});	
	});
   function saveSummary(rowindex){
		var  skuId =  $("#"+rowindex+"skuId").val();
		if(!numberFlag||skuId==""){
			setMessage("alert-warning","请检查数据填写是否正确");
			return;
	   }
	   var  skuSummaryQty =  $("#"+rowindex+"skuSummaryQty").val();
	   var  skuSummaryPrice =  $("#"+rowindex+"skuSummaryPrice").val();
	   var  skuSummaryOrderTime =  $("#"+rowindex+"skuSummaryOrderTime").val();
	   var  skuSummaryRukuTime =  $("#"+rowindex+"skuSummaryRukuTime").val();
	   var  skuSummaryRukuChecker =  $("#"+rowindex+"skuSummaryRukuChecker").val();
	   var  skuSummaryRukuComment =  $("#"+rowindex+"skuSummaryRukuComment").val();
	   var  skuSummarySellTime =  $("#"+rowindex+"skuSummarySellTime").val();
	   var  skuSummarySellPrice =  $("#"+rowindex+"skuSummarySellPrice").val();
	   var url = "${server}/summary/savesummary";
	 /*   var summarydata = "skuId:"+skuId+",skuSummaryQty:"+skuSummaryQty+",skuSummaryPrice:"+skuSummaryPrice+
		   ",skuSummaryOrderTime:"+skuSummaryOrderTime+",skuSummaryRukuTime:"+skuSummaryRukuTime+
		   ",skuSummaryRukuChecker:"+skuSummaryRukuChecker+",skuSummaryRukuComment:"+skuSummaryRukuComment+
		   ",skuSummarySellTime:"+skuSummarySellTime+",skuSummarySellPrice:"+skuSummarySellPrice; */
		var summarydata = "skuId="+skuId+"&skuSummaryQty="+skuSummaryQty+"&skuSummaryPrice="+skuSummaryPrice+
		 	"&skuSummaryOrderTime="+skuSummaryOrderTime+"&skuSummaryRukuTime="+skuSummaryRukuTime+
		   "&skuSummaryRukuChecker="+skuSummaryRukuChecker+"&skuSummaryRukuComment="+skuSummaryRukuComment+
		   "&skuSummarySellTime="+skuSummarySellTime+"&skuSummarySellPrice="+skuSummarySellPrice;
	   $.ajax({
			type: "POST",
			url:url,
	       	data:summarydata,
			type:'post',
			success:function(data){
				if("success"==data){
					setMessage("alert-success","保存成功！2秒后更新页面");
		       		window.setTimeout(function (){
		       		 	window.location.href="${server}/summary/list/";
		       		} ,2000);
				}else{
					setMessage("alert-danger","操作失败！");
				}
			}
		   
	   })  
	   
   }
   function setMessage(classstr,message){
		$('#message').html(message);
		$('#messageDiv').attr("class","alert alert-dismissable").addClass(classstr).show();
	}
   
   function validate(obj){
	    var reg = /^[0-9]+\.?[0-9]*$/;
	    if(!reg.test(obj.value)){
	    	numberFlag = false;
	    	obj.style.borderColor="red";
	    } else{
	    	numberFlag = true;
	    	obj.style.borderColor="";
	    }
	}  
   function qtychange(row){
	   var qty = $('#'+row+'skuSummaryQty').val();
		var discountPrice = $('#'+row+'discountPrice').val();
	   if(qty!=""&&discountPrice!=""){
		   $('#'+row+'skuSummaryPrice').val(Math.round(Number(qty)*Number(discountPrice) * 100) / 100);
	   }
   }   
	</script>

</head>
<body data-spy="scroll" data-target=".navbar" data-offset="50">
<%@include file="../common/header.jsp"%>
<input type="hidden" id="server" value="${server}">
<form action="" id="pagerForm"  method="post">
	<div class="container">
		<div id="tableDiv">
			<!-- alert-success alert-info alert-warning alert-danger-->
			<div class="alert alert-dismissable" id="messageDiv"  style="display: none;" >
				   <button type="button" class="close" data-dismiss="alert" 
				      aria-hidden="true">
				      &times;
				   </button>
				 	<span id="message"></span>
			</div>
			<table class="table table-bordered table-hover  table-striped" contenteditable="true">
				<thead >
					<tr>
						<th style="min-width :50px">操作</th>
						<th style="min-width :60px">状态</th>
						<th style="min-width :50px">品牌</th>
						<th style="min-width :50px">货号</th>
						<th style="min-width :50px">图片</th>
						<th style="min-width :50px">文件名</th>
						<th style="min-width :50px">描述</th>
						<th style="min-width :50px">单价€</th>
						<th style="min-width :50px">折扣(%off)</th>
						<th style="min-width :50px">折后价€</th>
						<th style="min-width :50px">预定价¥</th>
						<th style="min-width :50px">数量</th>
						<th style="min-width :80px">总价</th>
						<th style="min-width :100px">下单时间</th>
						<th style="min-width :100px">入库时间</th>
						<th style="min-width :80px">入库验收人</th>
						<th style="min-width :100px">入库备注</th>
						<th style="min-width :100px">售出时间</th>
						<th style="min-width :80px">实际售价</th>
					</tr>
				</thead>
				<tbody>
					<c:if test="${! empty summaryList}">
					<c:forEach  items="${summaryList}" var="summ" varStatus="status">
							<tr>
								<td>
									<a href="javascript:;" onclick="saveSummary('${status.index}')" >保存</a>
									<input type="hidden" value="${summ.skuId }" id="${status.index}skuId">
								</td>
								<td>${SkuStatusMap[summ.skuStatus]}</td>
								<td>${summ.merchandiseBrandName}</td>
								<td>${summ.skuPartNumber}</td>
								<td>
									<c:if test="${! empty summ.skuPicUrl}">
									<img src="/excelimg/${summ.skuPicUrl}" width="100px" ></c:if>
								</td>
								<td>${summ.quotationName}</td>
								<td <c:if test="${fn:length(summ.merchandiseDesc)>6}">style="min-width :100px"</c:if>>
									${summ.merchandiseDesc}</td>
								<td>${summ.skuPrice}</td>
								<td>${summ.skuPriceDiscount}</td>
								<td>
									<input id="${status.index}discountPrice" value ="<fmt:formatNumber  value="${summ.skuPrice*summ.skuPriceDiscount}"  pattern="0.0#"/>" type="hidden">
									<fmt:formatNumber  value="${summ.skuPrice*summ.skuPriceDiscount}"  pattern="0.0#"/>
								</td>
								<td>${summ.pricePrice}</td>
								<td><input type="text" style="width:100%" value="${summ.skuSummary.skuSummaryQty}" id="${status.index}skuSummaryQty" onchange="validate(this);qtychange(${status.index})"></td>
								<td>
									<c:if test="${empty summ.skuSummary.skuSummaryQty}">
									<input type="text" style="width:100%" value="${summ.skuSummary.skuSummaryPrice}" id="${status.index}skuSummaryPrice" disabled="disabled">
									</c:if>
									<c:if test="${!empty summ.skuSummary.skuSummaryQty}">
									<input type="text" style="width:100%" value="<fmt:formatNumber value='${summ.skuSummary.skuSummaryQty * summ.skuPrice*summ.skuPriceDiscount}' pattern='0.0#'></fmt:formatNumber>" id="${status.index}skuSummaryPrice" disabled="disabled">
									</c:if>
								</td>
								<td>
									<div class="input-append date" name="datetimepicker" data-date-format="yyyy-mm-dd">
										<input class="span2" type="text" style="width:100%" readonly="readonly" id="${status.index}skuSummaryOrderTime"
										value="<fmt:formatDate value="${summ.skuSummary.skuSummaryOrderTime}" pattern="yyyy-MM-dd"/>" >
										<span class="add-on"><i class="icon-remove"><div class="glyphicon glyphicon-remove"></div></i></span> 
										<span class="add-on pull-right"><i class="icon-th"><div class="glyphicon glyphicon-calendar"></div></i></span>
									</div>
								</td>
								<td>
									<div class="input-append date" name="datetimepicker" data-date-format="yyyy-mm-dd">
										<input class="span2" type="text" style="width:100%" readonly="readonly" id="${status.index}skuSummaryRukuTime"
											value="<fmt:formatDate value="${summ.skuSummary.skuSummaryRukuTime}" pattern="yyyy-MM-dd"/>" >
										<span class="add-on"><i class="icon-remove"><div class="glyphicon glyphicon-remove"></div></i></span> 
										<span class="add-on pull-right"><i class="icon-th"><div class="glyphicon glyphicon-calendar"></div></i></span>
									</div>
								</td>
								<td><input type="text" style="width:100%" value="${summ.skuSummary.skuSummaryRukuChecker}" id="${status.index}skuSummaryRukuChecker"></td>
								<td><input type="text" style="width:100%" value="${summ.skuSummary.skuSummaryRukuComment}" id="${status.index}skuSummaryRukuComment"></td>
								<td>
									<div class="input-append date" name="datetimepicker" data-date-format="yyyy-mm-dd">
										<input class="span2" type="text" style="width:100%" readonly="readonly" id="${status.index}skuSummarySellTime"
										 value="<fmt:formatDate value="${summ.skuSummary.skuSummarySellTime}" pattern="yyyy-MM-dd"/>" >
										<span class="add-on"><i class="icon-remove"><div class="glyphicon glyphicon-remove"></div></i></span> 
										<span class="add-on pull-right"><i class="icon-th"><div class="glyphicon glyphicon-calendar"></div></i></span>
									</div>
								</td>
								<td><input type="text" style="width:100%" value="${summ.skuSummary.skuSummarySellPrice}" id="${status.index}skuSummarySellPrice" onchange="validate(this)"></td>
							</tr>
					</c:forEach>
					</c:if>
					
				</tbody>
			</table>

				<div class="form-group">
					<div class="col-sm-offset-4 col-sm-8">
						<button type="button" class="btn  btn-primary"
							onclick="javascript:window.location.href='${server }/quotation/list/';"
							contenteditable="true">返回</button>
					</div>
				</div>
			</div>
	</div>
</form>


</body>
</html>
